#!/usr/bin/perl

use warnings;
use strict;



my $BIN_UPDATE  = "../scripts/update_f.pl";
my $BIN_HEX2DEC = "../scripts/prefix_hex2dec.pl";

my $DRYRUN = 0;

my $DOUT = "../data/prefixes";

sub run
{
    my $c = shift;
    print STDERR $c."\n";
    system $c unless $DRYRUN;
}
# --

if ( scalar @ARGV != 4 ) {
    print STDERR "http://archive.routeviews.org/oix-route-views/\n";
    print STDERR "year mon day time!\n";
    print STDERR "e.g.: ./getoix.pl 2011 07 26 2200\n";
    exit -1;
}

my $year = shift @ARGV;
my $mon  = shift @ARGV;
my $day  = shift @ARGV;
my $time = shift @ARGV;

my $c;

my $fname_get = sprintf "oix-full-snapshot-%04d-%02d-%02d-%04d.bz2", $year, $mon, $day, $time;
my $wpath = sprintf "wget http://archive.routeviews.org/oix-route-views/%04d.%02d/%s", $year, $mon, $fname_get;

$c = "wget -P ./tmp/ $wpath";
run($c);

#my $tmp_in  = "./tmp/$fname_get";
#my $tmp_out = "./tmp/$fname_get";

my $fname_prefix = sprintf "prefixes.%04d-%02d-%02d-%04d.txt", $year, $mon, $day, $time;

$c = "$BIN_UPDATE ./tmp/$fname_get ./tmp/$fname_prefix";
run($c);

$c = "cat ./tmp/$fname_prefix | $BIN_HEX2DEC > ./tmp/tmp.txt";
run($c);

$c = "mv ./tmp/tmp.txt ./tmp/$fname_prefix";
run($c);

$c = "mv ./tmp/$fname_prefix ./$DOUT/$fname_prefix";
run($c);


__END__
